package chapter05_array;

/**
 * ClassName: BubbleArray
 * Package: chapter05_array
 * Description:
 *使用冒泡排序以下数组，int[] arr=new int[]{34,54,3,2,65,7,34,5,76,34};
 * @Author 安思宇
 * @Create 2025/2/27 15:49
 */
public class BubbleArray {
    public static void main(String[] args) {
        int[] arr=new int[]{34,54,3,2,65,7,34,5,76,34};
        int temp=0;
        //冒泡排序关键代码
        for (int k =0; k < arr.length-1; k++) {
            for (int i = 0; i <arr.length-1-k; i++) {
                if(arr[i]>arr[i+1]){
                    temp=arr[i];
                    arr[i]=arr[i+1];
                    arr[i+1]=temp;
                }
            }
            //遍历
            for (int j = 0; j < arr.length; j++) {
                System.out.print(arr[j]+",");
            }
            System.out.println();
        }

    }
}
